﻿using Autofac;
using Autofac.Integration.Mvc;
using System.Reflection;
using Ebook.Data.Abstract;
using System.Web.Mvc;
using Ebook.Data.Concrete;
using Ebook.Models;
using Ebook.Services.Mapping;
using Ebook.Services.Services;


namespace Ebook.UI.App_Start
{
    public static class Bootstrapper
    {
        public static void Run()
        {
            StratRegister();
            AutoMapping.InitMapping();
        }
        /// <summary>
        /// 进行IoC类型注册
        /// </summary>
        public static void StratRegister()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType<EbookContext>();
            //泛型注册IRepository<>仓库接口
            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>));
            //注册Services服务接口
            builder.RegisterType<AdminServices>().As<IAdminServices>();
            builder.RegisterType<CustomerServices>().As<ICustomerServices>();

            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }


    }
 
}